//
//  CourseVideoViewMenuFull.m
//  xpkc
//
//  Created by TopSage on 15/10/23.
//  Copyright (c) 2015年 TopSage. All rights reserved.
//

#import "CourseVideoViewMenuFull.h"
#import "VideoListModel.h"
@implementation CourseVideoViewMenuFull{
    UITableView *chapterTab;
    CGFloat scale;
    
    UIButton * _currentqQualityBtn;
    
}

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatMenuFullView];
    }
    
    return self;
}

- (void)creatMenuFullView{
    
    scale = SCREEN_HEIGHT/SCREEN_WIDTH;//放大比例
    
    CGRect frame_top;
    CGRect frame_btn_back;
    CGRect frame_label_title;
    CGRect frame_btn_ask;
    CGRect frame_btn_quality;
    
    CGRect frame_bottom;
    CGRect frame_progress;
    CGRect frame_label_time;
    CGRect frame_btn_priv;
    CGRect frame_btn_play;
    CGRect frame_btn_next;
    CGRect frame_btn_fav;
    CGRect frame_btn_rate;
    CGRect frame_btn_chapter;
    CGRect frame_btn_half;
    
    CGRect frame_view_quality;
    CGRect frame_view_chapter;
    CGRect frame_view_rate;
    
    
    frame_top           = CGRectMake(0, 0, SCREEN_WIDTH, 58/scale);
    frame_btn_back      = CGRectMake(5, 25/scale, 28/scale, 28/scale);
    frame_label_title   = CGRectMake(44/scale, 20/scale, SCREEN_WIDTH - (50/scale +5)*4, 44/scale);
    frame_btn_ask       = CGRectMake(SCREEN_WIDTH - (50/scale +5)*2, 20/scale, 50/scale, 27/scale);
    frame_btn_quality   = CGRectMake(SCREEN_WIDTH - (50/scale +5)*1, 20/scale, 50/scale, 27/scale);
    frame_bottom        = CGRectMake(0, self.frame.size.height-58/scale, SCREEN_WIDTH, 64/scale);
    frame_progress      = CGRectMake(0, 0, SCREEN_HEIGHT, 1);//等待
    frame_label_time    = CGRectMake(5, 20/scale, 100/scale, 27/scale);
    //    frame_btn_priv      = CGRectMake(SCREEN_WIDTH/2 - 96/scale, 0, 64/scale, 64/scale);
    //    frame_btn_play      = CGRectMake(SCREEN_WIDTH/2 - 32/scale, 0, 64/scale, 64/scale);
    //    frame_btn_next      = CGRectMake(SCREEN_WIDTH/2 + 32/scale, 0, 64/scale, 64/scale);
    
    if (SCREEN_WIDTH < 375) {
        frame_btn_priv      = CGRectMake(SCREEN_WIDTH/2 - 96/scale - 15, 0, 64/scale, 64/scale);
        frame_btn_play      = CGRectMake(SCREEN_WIDTH/2 - 32/scale - 15, 0, 64/scale, 64/scale);
        frame_btn_next      = CGRectMake(SCREEN_WIDTH/2 + 32/scale - 15, 0, 64/scale, 64/scale);
        
    }else{
        
        frame_btn_priv      = CGRectMake(SCREEN_WIDTH/2 - 96/scale, 0, 64/scale, 64/scale);
        frame_btn_play      = CGRectMake(SCREEN_WIDTH/2 - 32/scale, 0, 64/scale, 64/scale);
        frame_btn_next      = CGRectMake(SCREEN_WIDTH/2 + 32/scale, 0, 64/scale, 64/scale);
        
    }
    
    frame_btn_fav       = CGRectMake(SCREEN_WIDTH - (50/scale+5)*2 -5 -27/scale, 20/scale, 27/scale, 27/scale);
    frame_btn_rate      = CGRectMake(SCREEN_WIDTH - (50/scale+5)*3, 20/scale, 50/scale, 27/scale);
    frame_btn_chapter   = CGRectMake(SCREEN_WIDTH - (50/scale+5)*2, 20/scale, 50/scale, 27/scale);
    frame_btn_half      = CGRectMake(SCREEN_WIDTH - (50/scale+5)*1, 20/scale, 50/scale, 27/scale);
    frame_view_chapter  = CGRectMake(SCREEN_WIDTH, 0, self.frame.size.height/scale, self.frame.size.height);
    frame_view_quality  = CGRectMake(SCREEN_WIDTH, 60/scale, (50/scale+5)*3, 40/scale);
    
    
    
    frame_view_rate     = CGRectMake(SCREEN_WIDTH, self.frame.size.height-100/scale, (50/scale+5)*3+5, 40/scale);
    
    //top
    self.topView = [[UIView alloc]initWithFrame:frame_top];
    self.topView.backgroundColor = [UIColor colorWithRed:0.4 green:0.4 blue:0.4 alpha:0.3];
    [self addSubview:self.topView];
    
    self.backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.backBtn.frame = frame_btn_back;
    [self.backBtn setImage:[UIImage imageNamed:@"back1"] forState:UIControlStateNormal];
    [self.topView addSubview:self.backBtn];
    
    self.titleLabel = [[UILabel alloc]initWithFrame:frame_label_title];
    self.titleLabel.font = [UIFont systemFontOfSize:17/scale];
    self.titleLabel.textColor = [UIColor whiteColor];
    self.titleLabel.text = @"课程标题：第一百二十七章";
    [self.topView addSubview:self.titleLabel];
    
//    self.favBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.favBtn.frame = frame_btn_fav;
    [self.favBtn setImage:[UIImage imageNamed:@"heart_white"] forState:UIControlStateNormal];
    [self.favBtn setImage:[UIImage imageNamed:@"heart_red"] forState:UIControlStateSelected];
    self.favBtn.titleLabel.font = [UIFont systemFontOfSize:15/scale];
    self.favBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    [self.topView addSubview:self.favBtn];
    
    self.questBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.questBtn.frame = frame_btn_ask;
    [self.questBtn setTitle:@"提问" forState:UIControlStateNormal];
    self.questBtn.titleLabel.font = [UIFont systemFontOfSize:15/scale];
    self.questBtn.layer.cornerRadius = 3/scale;
    self.questBtn.layer.borderWidth = 1/scale;
    self.questBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    [self.topView addSubview:self.questBtn];
    
    self.qualityBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.qualityBtn.frame = frame_btn_quality;
    [self.qualityBtn setTitle:@"画质" forState:UIControlStateNormal];
    self.qualityBtn.titleLabel.font = [UIFont systemFontOfSize:15/scale];
    self.qualityBtn.layer.cornerRadius = 3/scale;
    self.qualityBtn.layer.borderWidth = 1/scale;
    self.qualityBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    [self.topView addSubview:self.qualityBtn];
    
    
    //bottom
    self.bottomView = [[UIView alloc]initWithFrame:frame_bottom];
    self.bottomView.backgroundColor = [UIColor colorWithRed:0.4 green:0.4 blue:0.4 alpha:0.3];
    //    self.bottomView.backgroundColor = [UIColor redColor];
    [self addSubview:self.bottomView];
    
    self.timeLabel = [[UILabel alloc]initWithFrame:frame_label_time];
    self.timeLabel.font = [UIFont systemFontOfSize:15/scale];
    self.timeLabel.textColor = [UIColor whiteColor];
    self.timeLabel.text = @"00:00/00:00";
    [self.bottomView addSubview:self.timeLabel];
    
    self.progressView = [[UISlider alloc]initWithFrame:frame_progress];
    self.progressView.minimumValue = 0;
    self.progressView.maximumValue = 1;
    [self.bottomView addSubview:self.progressView];
    
    UIImage *leftImg =
    [[UIImage imageNamed:@"leftSlider5"]stretchableImageWithLeftCapWidth:1 topCapHeight:0];
    UIImage *rightImg =
    [[UIImage imageNamed:@"rightSlider5"]stretchableImageWithLeftCapWidth:1 topCapHeight:0];
    [self.progressView setMinimumTrackImage:leftImg forState:UIControlStateNormal];
    [self.progressView setMaximumTrackImage:rightImg forState:UIControlStateNormal];
    if (!isPad) {
        [self.progressView setThumbImage:[UIImage imageNamed:@"player_redbutton"] forState:UIControlStateNormal];
        [self.progressView setThumbImage:[UIImage imageNamed:@"player_redbutton_down"] forState:UIControlStateHighlighted];
    }else{
        [self.progressView setThumbImage:[UIImage imageNamed:@"player_redbutton"] forState:UIControlStateNormal];
        [self.progressView setThumbImage:[UIImage imageNamed:@"player_redbutton_down"] forState:UIControlStateHighlighted];
    }
    
    
    self.previBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.previBtn.frame = frame_btn_priv;
    [self.previBtn setImage:[UIImage imageNamed:@"ic_retreat_media"] forState:UIControlStateNormal];
    [self.bottomView addSubview:self.previBtn];
    
    self.playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.playBtn.frame = frame_btn_play;
    [self.playBtn setImage:[UIImage imageNamed:@"ic_play_media"] forState:UIControlStateNormal];
    [self.playBtn setImage:[UIImage imageNamed:@"ic_stop_media"] forState:UIControlStateSelected];
    [self.bottomView addSubview:self.playBtn];
    
    self.nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.nextBtn.frame = frame_btn_next;
    [self.nextBtn setImage:[UIImage imageNamed:@"ic_next_play"] forState:UIControlStateNormal];
    [self.bottomView addSubview:self.nextBtn];
    
    
    self.rateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.rateBtn.frame = frame_btn_rate;
    [self.rateBtn setTitle:@"1.0X" forState:UIControlStateNormal];
    self.rateBtn.titleLabel.font = [UIFont systemFontOfSize:15/scale];
    self.rateBtn.layer.cornerRadius = 3/scale;
    self.rateBtn.layer.borderWidth = 1/scale;
    self.rateBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    [self.bottomView addSubview:self.rateBtn];
    
    self.chaptersBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.chaptersBtn.frame = frame_btn_chapter;
    [self.chaptersBtn setTitle:@"章节" forState:UIControlStateNormal];
    self.chaptersBtn.titleLabel.font = [UIFont systemFontOfSize:15/scale];
    self.chaptersBtn.layer.cornerRadius = 3/scale;
    self.chaptersBtn.layer.borderWidth = 1/scale;
    self.chaptersBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    [self.bottomView addSubview:self.chaptersBtn];
    
    self.halfBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.halfBtn.frame = frame_btn_half;
    [self.halfBtn setTitle:@"半屏" forState:UIControlStateNormal];
    self.halfBtn.titleLabel.font = [UIFont systemFontOfSize:15/scale];
    self.halfBtn.layer.cornerRadius = 3/scale;
    self.halfBtn.layer.borderWidth = 1/scale;
    self.halfBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    [self.bottomView addSubview:self.halfBtn];
    
    //chapterview
    self.chaptersView = [[UIView alloc]initWithFrame:frame_view_chapter];
    self.chaptersView.backgroundColor = [UIColor colorWithRed:0.3 green:0.3 blue:0.3 alpha:0.3];
    self.isChapterClose = YES;
    [self addSubview:self.chaptersView];
    
    UILabel *chapterLabel  =[[UILabel alloc]initWithFrame:CGRectMake(0, 20/scale, self.chaptersView.width, 20/scale)];
    chapterLabel.textColor = [UIColor whiteColor];
    chapterLabel.font = [UIFont systemFontOfSize:16/scale];
    chapterLabel.text = @"章节";
    chapterLabel.textAlignment = NSTextAlignmentCenter;
    [self.chaptersView addSubview:chapterLabel];
    
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(10, 40/scale, self.chaptersView.width - 20, 1/scale)];
    line.backgroundColor = [UIColor whiteColor];
    [self.chaptersView addSubview:line];
    
    chapterTab = [[UITableView alloc]initWithFrame:CGRectMake(0, 41/scale, self.chaptersView.width, self.chaptersView.height - 41/scale) style:UITableViewStylePlain];
    chapterTab.delegate = self;
    chapterTab.dataSource = self;
    chapterTab.backgroundColor = CCOLOR;
    [self.chaptersView addSubview:chapterTab];
    chapterTab.tableFooterView = [[UILabel alloc] init];
    
    //rateview
    self.rateView = [[UIView alloc]initWithFrame:frame_view_rate];
    self.rateView.backgroundColor = [UIColor colorWithRed:0.3 green:0.3 blue:0.3 alpha:0.3];
    [self addSubview:self.rateView];
    
    UIButton *btnSlow = [UIButton buttonWithType:UIButtonTypeCustom];
    btnSlow.frame = CGRectMake(5+(50/scale+5)*0, 5/scale, 50/scale, 27/scale);
    btnSlow.tag = PlayerRateSlow;
    [btnSlow setTitle:@"0.8X" forState:UIControlStateNormal];
    btnSlow.titleLabel.font = [UIFont systemFontOfSize:15/scale];
    btnSlow.titleLabel.shadowOffset = CGSizeMake(1/scale, 1/scale);
    btnSlow.layer.cornerRadius = 3/scale;
    btnSlow.layer.borderWidth = 1/scale;
    btnSlow.layer.borderColor = [UIColor whiteColor].CGColor;
    [btnSlow setTitleShadowColor:[UIColor clearColor] forState:UIControlStateNormal];
    [btnSlow setTitleShadowColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [btnSlow addTarget:self action:@selector(rateBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.rateView addSubview:btnSlow];
    
    UIButton *btnNormal = [UIButton buttonWithType:UIButtonTypeCustom];
    btnNormal.frame = CGRectMake(5+(50/scale+5)*1, 5/scale, 50/scale, 27/scale);
    btnNormal.tag = PlayerRateNormal;
    [btnNormal setTitle:@"1.0X" forState:UIControlStateNormal];
    btnNormal.titleLabel.shadowOffset = CGSizeMake(1/scale, 1/scale);
    btnNormal.titleLabel.font = [UIFont systemFontOfSize:15/scale];
    btnNormal.layer.cornerRadius = 3/scale;
    btnNormal.layer.borderWidth = 1/scale;
    btnNormal.layer.borderColor = [UIColor whiteColor].CGColor;
    [btnNormal setTitleShadowColor:[UIColor clearColor] forState:UIControlStateNormal];
    [btnNormal setTitleShadowColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [btnNormal addTarget:self action:@selector(rateBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.rateView addSubview:btnNormal];
    self.currentRate = PlayerRateNormal;
    
    UIButton *btnFast = [UIButton buttonWithType:UIButtonTypeCustom];
    btnFast.frame = CGRectMake(5+(50/scale+5)*2, 5/scale, 50/scale, 27/scale);
    btnFast.tag = PlayerRateFast;
    [btnFast setTitle:@"1.5X" forState:UIControlStateNormal];
    btnFast.titleLabel.shadowOffset = CGSizeMake(1/scale, 1/scale);
    btnFast.titleLabel.font = [UIFont systemFontOfSize:15/scale];
    btnFast.layer.cornerRadius = 3/scale;
    btnFast.layer.borderWidth = 1/scale;
    btnFast.layer.borderColor = [UIColor whiteColor].CGColor;
    [btnFast setTitleShadowColor:[UIColor clearColor] forState:UIControlStateNormal];
    [btnFast setTitleShadowColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [btnFast addTarget:self action:@selector(rateBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.rateView addSubview:btnFast];
    
    //qualityview
    self.quelityView = [[UIView alloc]initWithFrame:frame_view_quality];
    self.quelityView.backgroundColor = [UIColor colorWithRed:0.3 green:0.3 blue:0.3 alpha:0.3];
    
    [self addSubview:self.quelityView];
    
    NSArray  * views = self.quelityView.subviews;
    
    for (UIView * view in views) {
        
        [view removeFromSuperview];
    }
    self.myblock = ^(NSDictionary * playUrls){
        
        
        
        
        CGFloat btnW = (50 / scale);
        
        NSArray *array = [playUrls objectForKey:@"qualities"];
        int i = 0;
        
        if (array.count <= 2) {
            CGRect qulityframe = self.quelityView.frame;
            qulityframe.origin.x += btnW + 3;
            self.quelityView.frame = qulityframe;
        }
        
        for ( NSDictionary * qualitiesDic in array)  {
            
            UIButton * button = [[UIButton alloc] initWithFrame:CGRectMake(3 + (btnW + 3)* i, 0, btnW, 20)];
            [button setTitle:qualitiesDic[@"desp"] forState:UIControlStateNormal];
            //            button.backgroundColor = [UIColor colorWithRed:0.3 green:0.3 blue:0.3 alpha:0.3];
            [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            button.tag = i ;//[qualitiesDic[@"quality"] integerValue];
            button.titleLabel.font = [UIFont systemFontOfSize:13];
            button.layer.cornerRadius = 5;
            button.layer.masksToBounds = YES;
            button.titleLabel.font = [UIFont systemFontOfSize:10];
            //            if (i == 0) {
            //
            //                [button setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
            //                button.backgroundColor = [UIColor lightGrayColor];
            //
            //
            //            }
            [button addTarget:self action:@selector(chooseQulity:) forControlEvents:UIControlEventTouchUpInside];
            //            _currentqQualityBtn = button;
            [self.quelityView addSubview:button];
            
            i ++;
        }
        
        
    };
    
    
    
    CGFloat height = SCREEN_HEIGHT>SCREEN_WIDTH?SCREEN_HEIGHT:SCREEN_WIDTH;
    CGFloat width = SCREEN_HEIGHT>SCREEN_WIDTH?SCREEN_WIDTH:SCREEN_HEIGHT;
    
    
    // 音量
    
    self.volumeView = [[UIView alloc]init];
    CGRect volume_view_frame;
    volume_view_frame = CGRectMake(0, (width-(width-20*2))/2 +20, 30, width-55*2-20*2 - 100);
    
    if (SCREEN_HEIGHT <= 480) {
        volume_view_frame = CGRectMake(0, (width-(width-20*2))/2 +20 + 5, 20, width- 60 -20*2 - 100-3);
    }
    if (SCREEN_HEIGHT <= 568 && SCREEN_HEIGHT > 480) {
        volume_view_frame = CGRectMake(0, (width-(width-20*2))/2 +20 , 20, width- 85-20*2 - 100);
    }
    
    self.volumeView.frame = volume_view_frame;
    self.volumeView.backgroundColor = [UIColor colorWithRed:0.4 green:0.4 blue:0.4 alpha:0.6];
    self.volumeView.layer.cornerRadius = 5;
    [self addSubview:self.volumeView];
    
    
//    self.volume = [[UIImageView alloc]init];
    CGRect volume_frame;
    
    //    volume_frame = RECT(height/2-240, width/2, 96, 116);
    volume_frame = RECT(height/2-150, width/2+30, 48, 58);
    self.volume.frame = volume_frame;
    self.volume.image=[UIImage imageNamed:@"player_sound"];
    [self addSubview:self.volume];
    
    //    self.volume.backgroundColor = [UIColor redColor];
    self.schedule = [[UIImageView alloc]init];
    CGRect schedule_frame;
    //    schedule_frame = RECT(height/2+104, width/2+50, 96, 116);
    schedule_frame = RECT(height/2+102, width/2+30, 48, 58);
    self.schedule.frame= schedule_frame;
    self.schedule.image=[UIImage imageNamed:@"player_progress"];
    [self addSubview:self.schedule];
    //    self.backgroundColor = [UIColor magentaColor];
    
    self.volumeSlider = [[UISlider alloc]init];
    CGRect volume_slider_frame;
    volume_slider_frame = CGRectMake(-35, 50, 100, 1);
    
    //    NSLog(@"%f--%f",SCREEN_WIDTH,SCREEN_HEIGHT);
    
    if (SCREEN_HEIGHT <= 480) {
        
        volume_slider_frame = CGRectMake(-38, 53, 95, 1);
    }
    
    if (SCREEN_HEIGHT <= 568 && SCREEN_HEIGHT > 480) {
        volume_slider_frame = CGRectMake(-30, 40, 80, 1);
    }
    
    //    volume_slider_frame = CGRectMake(-35, 55, 100, 100);
    self.volumeSlider.frame = volume_slider_frame;
    
    self.volumeSlider.minimumValue = 0.0;
    self.volumeSlider.maximumValue = 1.0;
    self.volumeSlider.transform = CGAffineTransformMakeRotation(M_PI*-0.5);
    self.volumeSlider.minimumTrackTintColor = [UIColor orangeColor];
    
    if (!isPad) {
        [self.volumeSlider setThumbImage:[UIImage imageNamed:@"player_redbutton2"] forState:UIControlStateNormal];
        [self.volumeSlider setThumbImage:[UIImage imageNamed:@"player_redbutton_down2"] forState:UIControlStateHighlighted];
    }else{
        [self.volumeSlider setThumbImage:[UIImage imageNamed:@"player_redbutton2"] forState:UIControlStateNormal];
        [self.volumeSlider setThumbImage:[UIImage imageNamed:@"player_redbutton_down2"] forState:UIControlStateHighlighted];
    }
    
    
    
    [self.volumeView addSubview:self.volumeSlider];
    
    self.volumeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    CGRect volume_btn_frame;
    volume_btn_frame = CGRectMake(10+8 - 13, width-97*2-120*2-40 + 90 + 100 + 14, 20, 15);
    
    if (SCREEN_HEIGHT <= 480) {
        volume_btn_frame = CGRectMake(5+8 - 13, width-97*2-120*2-40 + 90 + 100 + 14 + 50, 20, 15);
    }
    if (SCREEN_HEIGHT <= 568 && SCREEN_HEIGHT > 480) {
        volume_btn_frame = CGRectMake(5+8 - 13, width-97*2-120*2 - 40 - 6 + 90 + 100 +  50, 20, 15);
    }
    //    volume_btn_frame = CGRectMake(10, width-55*2-20*2-30+100, 20, 15);
    self.volumeBtn.frame = volume_btn_frame;
    [self.volumeBtn setImage:[UIImage imageNamed:@"player_volume_middle"] forState:UIControlStateNormal];
    [self.volumeBtn setImage:[UIImage imageNamed:@"player_volume_zero"] forState:UIControlStateSelected];
    [self.volumeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.volumeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    self.volumeBtn.userInteractionEnabled = YES;
    //    self.volumeBtn.backgroundColor = [UIColor redColor];
    self.volumeBtn.titleLabel.font = FONT_SYS_NORMAL;
    [self.volumeView addSubview:self.volumeBtn];
    
    // frame_bottom        = CGRectMake(0, self.frame.size.height-58/scale, SCREEN_WIDTH, 64/scale);
    
    
    self.qualitiesNoteLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width * 0.5 - 40, self.frame.size.height*0.5, 80, 40/scale)];
    
    self.qualitiesNoteLabel.backgroundColor = [UIColor colorWithRed:0.3 green:0.3 blue:0.3 alpha:0.3];
    self.qualitiesNoteLabel.hidden = YES;
    self.qualitiesNoteLabel.textColor = [UIColor whiteColor];
    self.qualitiesNoteLabel.text = @"切换中...";
    self.qualitiesNoteLabel.font = [UIFont systemFontOfSize:14];
    [self addSubview:self.qualitiesNoteLabel];
    
}

-(void)chooseQulity:(UIButton *)btn{
    
    
    
    NSLog(@"%ld--%ld",btn.tag,self.currentQuality);
    if (btn.tag == self.currentQuality) {
        
        [self closeQuality];
        return;
    }
    if ([self.delegate respondsToSelector:@selector(qualityBtnClick:)]) {
        self.currentQuality = btn.tag;
        //        _currentqQualityBtn.backgroundColor = [UIColor redColor];//[UIColor colorWithRed:0.3 green:0.3 blue:0.3 alpha:0.3];
        //        _currentqQualityBtn = btn;
        //
        //        btn.backgroundColor = [UIColor darkGrayColor];
        
        
        [self.delegate qualityBtnClick:btn];
    }
    
}

- (void)closeMenu{
    self.isClose = YES;
    [self closeQuality];
    [self closeRate];
    [UIView animateWithDuration:0.4 animations:^{
        self.topView.top = -self.topView.height;
        self.bottomView.top = self.bottomView.top + self.bottomView.height;
        
        self.volumeView.left -= self.volumeView.width;
        //        self.volume.left -= SCREEN_WIDTH;
    }];
}

- (void)openMenu{
    self.isClose = NO;
    [UIView animateWithDuration:0.4 animations:^{
        self.topView.top = 0;
        self.bottomView.top = self.bottomView.top - self.bottomView.height;
        
        self.volumeView.left += self.volumeView.width;
    }];
}
- (void)closeChapter{
    self.isChapterClose = YES;
    [self openMenu];
    [UIView animateWithDuration:0.4 animations:^{
        self.chaptersView.left = self.chaptersView.left + self.chaptersView.width;
    }];
}
- (void)openChapter{
    self.isChapterClose = NO;
    [self closeMenu];
    [UIView animateWithDuration:0.4 animations:^{
        self.chaptersView.left = self.chaptersView.left - self.chaptersView.width;
    }];
}
- (void)openRate{
    [UIView animateWithDuration:0.4 animations:^{
        if (self.rateView.left >= SCREEN_WIDTH-1) {
            self.rateBtn.selected = YES;
            self.rateView.left = self.rateView.left - self.rateView.width;
        }
    }];
}
- (void)closeRate{
    [UIView animateWithDuration:0.4 animations:^{
        if (self.rateView.left < SCREEN_WIDTH-1) {
            self.rateBtn.selected = NO;
            self.rateView.left = self.rateView.left + self.rateView.width;
        }
    }];
}
- (void)openQuality{
    [UIView animateWithDuration:0.4 animations:^{
        if (self.quelityView.left >= SCREEN_WIDTH-1) {
            self.qualityBtn.selected = YES;
            self.quelityView.left = self.quelityView.left - self.quelityView.width;
        }
    }];
}
- (void)closeQuality{
    [UIView animateWithDuration:0.4 animations:^{
        if (self.quelityView.left < SCREEN_WIDTH-1) {
            self.qualityBtn.selected = NO;
            self.quelityView.left = self.quelityView.left + self.quelityView.width;
        }
    }];
}
- (void)setChapters:(NSArray *)chapters{
    _chapters = chapters;
    [chapterTab reloadData];
}
- (void)setQualities:(NSArray *)qualities{
}

#pragma mark - delegate
- (void)rateBtnClick:(UIButton *)btn{
    [self closeRate];
    if (btn.tag == self.currentRate) {
        return;
    }
    if ([self.delegate respondsToSelector:@selector(rateBtnClick:)]) {
        [self.delegate rateBtnClick:btn];
    }
}
- (void)qualityBtnClick:(UIButton *)btn{
    if (btn.tag == self.currentQuality) {
        [self closeQuality];
        return;
    }
    if ([self.delegate respondsToSelector:@selector(qualityBtnClick:)]) {
        [self.delegate qualityBtnClick:btn];
    }
}
- (void)chapterSelectedAtIndex:(NSIndexPath *)indexpath{
    if (indexpath == self.currentIndexPath) {
        [self closeChapter];
        return;
    }
    if ([self.delegate respondsToSelector:@selector(chapterSelectedAtIndex:)]) {
        [self.delegate chapterSelectedAtIndex:indexpath];
    }
}

#pragma mark - tabdelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _chapters.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (_chapters.count>1) {
        NSDictionary *dict = [_chapters objectAtIndex:section];
        NSArray *array = [dict objectForKey:@"array"];
        return array.count;
    }
    return 0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    NSDictionary *dict = [_chapters objectAtIndex:section];
    NSString *title = [dict objectForKey:@"chapter"];
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, tableView.width, 30/scale)];
    label.text = title;
    label.textColor = [UIColor whiteColor];
    label.font = [UIFont systemFontOfSize:15/scale];
    label.backgroundColor = [UIColor colorWithRed:0.3 green:0.3 blue:0.3 alpha:1];
    return label;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 30/scale;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 40/scale;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    NSDictionary *dict = [_chapters objectAtIndex:indexPath.section];
    NSArray *array = [dict objectForKey:@"array"];
    VideoListModel *model = [array objectAtIndex:indexPath.row];
    cell.textLabel.text = model.title;
    cell.textLabel.textColor = [UIColor whiteColor];
    cell.textLabel.font = [UIFont systemFontOfSize:14/scale];
    cell.backgroundColor = [UIColor colorWithRed:0.3 green:0.3 blue:0.3 alpha:0.2];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    logdebug(@"%@",indexPath);
    if ([self.delegate respondsToSelector:@selector(chapterSelectedAtIndex:)]) {
        [self.delegate chapterSelectedAtIndex:indexPath];
    }
}

@end
